package com.boss.salary.service.impl;

import com.boss.salary.dao.IConfigCtrlDao;
import com.boss.salary.entity.ConfigCtrl;
import com.boss.salary.service.IConfigCtrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ConfigCtrlServicelmpl implements IConfigCtrlService {
    @Autowired
    private IConfigCtrlDao IConfigCtrlDao;

    @Override
    public List<ConfigCtrl> selectConfigCtrl(String province) {
        List<ConfigCtrl> list = IConfigCtrlDao.selectConfigCtrl(province);
        return list;
    }

    @Override
    public String selectBatchControl(String province) {
        String BatchControl = "";
        ConfigCtrl cc = new ConfigCtrl();
        cc.setConfigType("batchAble");
        cc.setIsAble("1");
        cc.setMofDivCode(province);
        int num = IConfigCtrlDao.selectBatchControl(cc);
        if(num>=1){
            BatchControl = "1";
        }else{
            BatchControl = "0";
        }
        return BatchControl;
    }


    @Override
    public String selectPersonImportControl(String province) {
        String personImportControl = "";
        ConfigCtrl cc = new ConfigCtrl();
        cc.setConfigType("personImportControl");
        cc.setIsAble("1");
        cc.setMofDivCode(province);
        int num = IConfigCtrlDao.selectBatchControl(cc);
        if(num>=1){
            personImportControl = "1";
        }else{
            personImportControl = "0";
        }
        return personImportControl;
    }




    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updataIsAbleConfigCtrl(String province,List<ConfigCtrl> configCtrls) {
        if (configCtrls.size() > 0) {
            // 先删除
            IConfigCtrlDao.deletedConfigCtrl(province);
            //保存
            IConfigCtrlDao.saveConfigCtrl(configCtrls, province);
        }
    }

}





